package com.leinao.model.controller;

import com.alibaba.fastjson.JSON;
import com.leinao.commons.Response;
import com.leinao.constant.Constant;
import com.leinao.constant.LoginEnum;
import com.leinao.constant.ModelEnum;
import com.leinao.constant.ModelErrorEnum;
import com.leinao.job.dto.JobInfoDto;
import com.leinao.login.dto.LoginResultDto;
import com.leinao.model.dto.JobDto;
import com.leinao.model.dto.ModelAttentionInfo;
import com.leinao.model.dto.ModelCategoryDto;
import com.leinao.model.dto.ProjectDto;
import com.leinao.model.model.Model;
import com.leinao.model.service.ModelService;
import com.leinao.team.dto.TeamMemberDto;
import com.leinao.util.page.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: weiwei
 * @Date: 2019/6/3 20:39
 * @Description:
 * @Version 1.0
 */
@RestController
@CrossOrigin
public class ModelController {

    private static Logger logger = LoggerFactory.getLogger(ModelController.class);

    @Autowired
    private ModelService modelService;

    @ApiOperation(value="关注/取消关注模型", notes="关注/取消关注模型")
    @GetMapping(value = "/model/attentionModel")
    public Response<Void> attentionModel(HttpServletRequest request,
                                         @ApiParam(value = "关注/取消关注模型") @RequestParam(required = true) Integer attentionFlag,
                                         @ApiParam(value = "模型Id") @RequestParam(required = true) Long modelId) {
        logger.info("attentionModel param: attentionFlag is {}, modelId is {}", attentionFlag, modelId);

        if(null == modelId){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelEnum.MODEL_ID_IS_EMPTY_ERROR.getSeq(),
                    ModelEnum.MODEL_ID_IS_EMPTY_ERROR.getDesc(), null);
        }
        if(null == attentionFlag){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelEnum.MODEL_ATTENTION_FLAG_EMPTY_ERROR.getSeq(),
                    ModelEnum.MODEL_ATTENTION_FLAG_EMPTY_ERROR.getDesc(), null);
        }

        if((!attentionFlag.equals(Constant.MODEL_NO_ATTENTION)) && (!attentionFlag.equals(Constant.MODEL_IS_ATTENTION))){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelEnum.MODEL_ATTENTION_FLAG_IS_ERROR.getSeq(),
                    ModelEnum.MODEL_ATTENTION_FLAG_IS_ERROR.getDesc(), null);
        }

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );
        if (null == userInfo || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.attentionModel(modelId, attentionFlag, userInfo);
    }

    @ApiOperation(value="删除模型", notes="删除模型")
    @GetMapping(value = "/model/deleteModel")
    public Response<Void> deleteModel(HttpServletRequest request,
                                         @ApiParam(value = "模型Id") @RequestParam(required = true) Long modelId) {
        logger.info("deleteModel param:  modelId is {}", modelId);

        if(null == modelId){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelEnum.MODEL_ID_IS_EMPTY_ERROR.getSeq(),
                    ModelEnum.MODEL_ID_IS_EMPTY_ERROR.getDesc(), null);
        }

        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );
        if (null == userInfo || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.deleteModel(modelId, userInfo);
    }

    @ApiOperation(value="获取用户是否关注模型", notes="获取用户身份关注模型")
    @GetMapping(value = "/getUserAttentionStatus")
    public Response<ModelAttentionInfo> getUserAttentionStatus(
                        @ApiParam(value = "模型Id", required = true) @RequestParam Long modelId,
                        HttpServletRequest request) {

        logger.info("getUserAttentionStatus param: modelId is {}", modelId);

        if(null == modelId){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelEnum.MODEL_ID_IS_EMPTY_ERROR.getSeq(),
                    ModelEnum.MODEL_ID_IS_EMPTY_ERROR.getDesc(), null);
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }
        return modelService.getUserAttentionStatus(modelId, userInfo);
    }


    @ApiOperation(value="平台用户公开的模型列表(不包含自己创建的)", notes="创建项目/编辑项目用")
    @GetMapping(value = "/getPublicModelsExceptOwn")
    public Response<PageInfo> getPublicModelsExceptOwn(
                    @ApiParam(value = "当前页", required = false) @RequestParam(required = false) Integer pageNumber,
                    @ApiParam(value = "每页条数", required = false) @RequestParam(required = false) Integer pageSize,
                    @ApiParam(value = "搜索内容") @RequestParam(required = false)  Long categoryId,
                        HttpServletRequest request) {

        logger.info("getPublicModelsExceptOwn param: pageNumber is {}, pageSize is {}, categoryId is {}", pageNumber, pageSize, categoryId);

        // 默认分页条件设置
        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }
        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getPublicModelsExceptOwn(pageNumber, pageSize, categoryId, userInfo);
    }

    @ApiOperation(value="平台用户公开的模型列表", notes="公开模型列表")
    @GetMapping(value = "/getPublicModels")
    public Response<PageInfo> getPublicModels(
            @ApiParam(value = "当前页", required = false) @RequestParam(required = false) Integer pageNumber,
            @ApiParam(value = "每页条数", required = false) @RequestParam(required = false) Integer pageSize,
            @ApiParam(value = "搜索内容") @RequestParam(required = false)  Long categoryId,
                                                HttpServletRequest request) {

        logger.info("getPublicModels param: pageNumber is {}, pageSize is {}, categoryId is {}", pageNumber, pageSize, categoryId);

        // 默认分页条件设置
        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getPublicModels(pageNumber, pageSize, categoryId, userInfo);
    }


    @ApiOperation(value="关注模型列表", notes="关注模型列表")
    @GetMapping(value = "/getAttentionModels")
    public Response<PageInfo> getAttentionModels(
            @ApiParam(value = "当前页", required = false) @RequestParam(required = false) Integer pageNumber,
            @ApiParam(value = "每页条数", required = false) @RequestParam(required = false) Integer pageSize,
                         HttpServletRequest request) {

        logger.info("getAttentionModels param: pageNumber is {}, pageSize is {}", pageNumber, pageSize);

        // 默认分页条件设置
        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getAttentionModels(pageNumber, pageSize, userInfo);
    }

    @ApiOperation(value="创建模型", notes="创建模型")
    @PostMapping(value = "/model/createModel")
    public Response<Void> createModel(HttpServletRequest request,
                                      @ApiParam(value = "模型名称") @RequestParam(required = true) String modelName,
                                      @ApiParam(value = "模型简介") @RequestParam(required = true) String modelIntroduction,
                                      @ApiParam(value = "项目ID") @RequestParam(required = false) Long projectId,
                                      @ApiParam(value = "语言") @RequestParam(required = false) String language,
                                      @ApiParam(value = "框架") @RequestParam(required = false) String framework,
                                      @ApiParam(value = "是否本地上传") @RequestParam(required = true) boolean localUpload,
                                      @ApiParam(value = "任务ID") @RequestParam(required = false) Long jobId)
    {
        logger.info("createModel param:  modelName is {},modelIntroduction is {},projectId is {},jobId is {}", modelName,modelIntroduction,projectId,jobId);
        if(modelName.length()>50){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelErrorEnum.MODELNAME_TOO_LONG.getSeq(), ModelErrorEnum.MODELNAME_TOO_LONG.getDesc(), null);
        }
        if(modelIntroduction.length()>6000){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelErrorEnum.MODELINTRODUCTION_TOO_LONG.getSeq(), ModelErrorEnum.MODELINTRODUCTION_TOO_LONG.getDesc(), null);
        }
        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );
        return modelService.createModel(userInfo.getUserId(),modelName,modelIntroduction,projectId,jobId,language,framework,localUpload);
    }
    @ApiOperation(value="获取项目信息", notes="获取项目信息")
    @GetMapping(value = "/model/getProName")
    public Response<List<ProjectDto>> getProName(HttpServletRequest request,
                                                 @ApiParam(value = "项目名") @RequestParam(required = false) String projectName
    )
    {
        logger.info("attentionModel param:  modelName is {},modelIntroduction is {},projectId is {},jobId is {}");
        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );
        Response<List<ProjectDto>> proName = modelService.getProName(userInfo.getUserId(),projectName);
        return proName;
    }
    @ApiOperation(value="任务信息", notes="获取任务信息")
    @GetMapping(value = "/model/getJobName")
    public Response<List<JobInfoDto>> getJobName(HttpServletRequest request,
        @ApiParam(value = "项目ID") @RequestParam(required = false) Long projectId,
        @ApiParam(value = "任务名") @RequestParam(required = false) String jobName
                                                 )
    {
        logger.info("attentionModel param:  modelName is {},modelIntroduction is {},projectId is {},jobId is {}");
        // 获取登录用户信息
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj,LoginResultDto.class );
        Response<List<JobInfoDto>> jobList = modelService.getJobName(projectId,jobName,userInfo);
        return jobList;
    }

    @ApiOperation(value="用户个人创建模型列表", notes="用户个人创建模型列表")
    @GetMapping(value = "/getUserOwnModels")
    public Response<PageInfo> getUserOwnModels(
            @ApiParam(value = "当前页", required = false) @RequestParam(required = false) Integer pageNumber,
            @ApiParam(value = "每页条数", required = false) @RequestParam(required = false) Integer pageSize,
            HttpServletRequest request) {

        logger.info("getUserOwnModels param: pageNumber is {}, pageSize is {}", pageNumber, pageSize);

        // 默认分页条件设置
        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getUserOwnModels(pageNumber, pageSize, userInfo);
    }


    @ApiOperation(value="用户个人模型列表", notes="创建项目 - 个人+关注")
    @GetMapping(value = "/getUserModels")
    public Response<PageInfo> getUserModels(
            @ApiParam(value = "当前页", required = false) @RequestParam(required = false) Integer pageNumber,
            @ApiParam(value = "每页条数", required = false) @RequestParam(required = false) Integer pageSize,
            HttpServletRequest request) {

        logger.info("getUserModels param: pageNumber is {}, pageSize is {}", pageNumber, pageSize);

        // 默认分页条件设置
        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getUserModels(pageNumber, pageSize, userInfo);
    }
    @ApiOperation(value="公开模型详情", notes="公开模型详情")
    @GetMapping(value = "/model/getModelDetail")
    public Response<Model> getProjectByModelId(
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            @ApiParam(value = "模型ID") @RequestParam(required = false) Integer type,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: modelId is {}", modelId);


        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getModelDetail(modelId,type,userInfo.getUserId());
    }
    @ApiOperation(value="公开模型详情项目列表", notes="模型详情项目列表")
    @GetMapping(value = "/model/getProjectByModelId")
    public Response<PageInfo> getProjectByModelId(
            @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
            @ApiParam(value = "每页条数") @RequestParam(required = false) Integer pageSize,
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            @ApiParam(value = "模型ID") @RequestParam(required = false) Integer type,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: pageNumber is {}, pageSize is {}", pageNumber, pageSize);

        // 默认分页条件设置
        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getProjectByModelId(modelId,type,userInfo.getUserId(),pageNumber, pageSize);
    }
    @ApiOperation(value="修改模型简介", notes="修改模型简介")
    @PostMapping(value = "/model/updateModelIntro")
    public Response<Integer> updateModelIntro(
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long id,
            @ApiParam(value = "模型简介") @RequestParam(required = false) String introduction,
            HttpServletRequest request) {
        logger.info("updateModelIntro param: id is {}, introduction is {}", id, id);
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }
        return modelService.updateModelIntro(id,userInfo.getUserId(),introduction);
    }
    @ApiOperation(value="我的模型详情", notes="我的模型详情")
    @GetMapping(value = "/model/getModelDetailForCreate")
    public Response<Model> getModelDetailForCreate(
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: modelId is {}", modelId);


        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getModelDetailForCreate(modelId,userInfo.getUserId());
    }
    @ApiOperation(value="我的模型详情项目列表", notes="我的模型详情项目列表")
    @GetMapping(value = "/model/getProjectByModelIdForCreate")
    public Response<PageInfo> getProjectByModelIdForCreate(
            @ApiParam(value = "当前页") @RequestParam(required = false) Integer pageNumber,
            @ApiParam(value = "每页条数") @RequestParam(required = false) Integer pageSize,
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            HttpServletRequest request) {

        logger.info("getProjectByModelIdForCreate param: pageNumber is {}, pageSize is {}", pageNumber, pageSize);

        // 默认分页条件设置
        if(pageSize == null || pageSize < Constant.DEFAULT_PAGE_NUMBER) {
            pageSize = Constant.DEFAULT_PAGE_SIZE;
        }

        if(pageNumber == null || pageNumber < Constant.DEFAULT_PAGE_NUMBER) {
            pageNumber = Constant.DEFAULT_PAGE_NUMBER;
        }

        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getProjectByModelIdForCreate(modelId,userInfo.getUserId(), pageNumber, pageSize);
    }
    @ApiOperation(value="公开模型", notes="公开模型")
    @PostMapping(value = "/model/openModel")
    public Response<Integer> openModel(
            @ApiParam(value = "标签") @RequestParam(required = false) Long[] tagList,
            @ApiParam(value = "用户") @RequestParam(required = false) String[] userList,
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            @ApiParam(value = "封面图片ID") @RequestParam(required = false) Long modelCoverId,
            @ApiParam(value = "是否公开给所有人") @RequestParam(required = false) Boolean openAll,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: modelId is {}", modelId);


        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }
        if(null==tagList||null==modelId){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelErrorEnum.MODEL_PARAM_IS_NULL.getSeq(), ModelErrorEnum.MODEL_PARAM_IS_NULL.getDesc(), null);
        }
        try {
            return modelService.openModel(userInfo.getUserId(),tagList,userList,modelId,modelCoverId,openAll);
        }catch (Exception e){
            String message = e.getMessage();
            if(ModelErrorEnum.YOU_CAN_NOT_OPEN_TO_YOURSELF.getDesc().equals(message)){
                return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelErrorEnum.YOU_CAN_NOT_OPEN_TO_YOURSELF.getSeq(), ModelErrorEnum.YOU_CAN_NOT_OPEN_TO_YOURSELF.getDesc(), null);
            }else {
                return Response.error(null);
            }
        }
    }

    @ApiOperation(value="获取已公开模型的人员信息", notes="获取已公开模型的人员信息")
    @GetMapping(value = "/model/getPersonalRelation")
    public Response<List<TeamMemberDto>> getPersonalRelation(
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: modelId is {}", modelId);


        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getPersonalRelation(modelId);
    }
    @ApiOperation(value="取消已公开模型的个人", notes="取消已公开模型的个人")
    @GetMapping(value = "/model/deletePersonalRelation")
    public Response<Integer> deletePersonalRelation(
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            @ApiParam(value = "模型ID") @RequestParam(required = false) String userId,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: modelId is {}", userId);


        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.deletePersonalRelation(modelId,userId);
    }
    @ApiOperation(value="获取已公开给个人的模型的标签列表", notes="获取已公开给个人的模型的标签列表")
    @GetMapping(value = "/model/getOpenCategory")
    public Response<List<ModelCategoryDto>> getOpenCategory(
            @ApiParam(value = "模型ID") @RequestParam(required = false) Long modelId,
            HttpServletRequest request) {

        logger.info("getProjectByModelId param: modelId is {}", modelId);


        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }

        return modelService.getOpenCategory(modelId);
    }

    @ApiOperation(value="获取模型是否公开", notes="获取模型是否公开")
    @GetMapping(value = "/model/getModelType")
    public Response<List<Model>> getModelType(
            @ApiParam(value = "模型ID") @RequestParam(required = false) String modelIds,
            HttpServletRequest request) {

        logger.info("getModelType param: modelIds is {}", modelIds);

        if(StringUtils.isBlank(modelIds)){
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, ModelEnum.MODELIDS_IS_EMPTY_EEEOR.getSeq(),
                                                                    ModelEnum.MODELIDS_IS_EMPTY_EEEOR.getDesc(), null);
        }
        String obj = (String) request.getSession().getAttribute(Constant.USER_SESSION_KEY);
        LoginResultDto userInfo = JSON.parseObject(obj, LoginResultDto.class);
        if (userInfo == null || StringUtils.isBlank(userInfo.getUserId())) {
            return Response.error(Constant.RESPONSE_STATUS_SUCCESS, LoginEnum.LOGIN_TIMEOUT.getSeq(), LoginEnum.LOGIN_TIMEOUT.getDesc(), null);
        }
        return modelService.getModelType(modelIds);
    }
}
